<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/23
 * Time: 20:49
 */

namespace app\api\controller\v1;
use app\api\service\UserToken;
use app\lib\exception\ParamersException;
use think\Controller;
use app\api\service\Token as TokenService;

class Token extends Controller
{

    public function getToken($code = '')
    {
        $validate = Validate('GetToken') -> check(['code' => $code]);
        if(!$validate) return Validate('GetToken') -> getError();
        $userId = new UserToken($code);
        $token = $userId -> getLoginCode();
        return ['token' => $token];
    }
    //验证令牌是否有效
    public function verifyToken(){
        $token = input('post.token');
        if(!$token){
            throw new paramersException(['msg' => 'token不能为空！']);
        }
        $result = TokenService::verify($token);
        return ['isvalide' => $result];
    }
}